﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using UDS.Components;

namespace UDS.SubModule.UnitiveDocument.DocumentFlowPages
{
    /// <summary>
    /// SelectProject 的摘要说明。
    /// </summary>
    public partial class SelectProjectPage : Page
    {
        private int DefineID;
        private int DocID;
        private string UserName;

        protected override void OnInit(EventArgs e)
        {
            cmdOK.Click += cmdOK_Click;
            cmdCancel.Click += cmdCancel_Click;
            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            UserName = SiteContext.Current.UserName;
            DocID = QSUtil.GetPositiveInt32("DocID");
            DefineID = QSUtil.GetPositiveInt32("DefineID");

            if (!Page.IsPostBack)
            {
                Bingding();
            }

            base.OnLoad(e);
        }

        private void Bingding()
        {
            var mySQL = new Database();
            SqlParameter[] p2 = {
                Database.MakeInParam("@StaffName", SqlDbType.NVarChar, 300, UserName)
            };

            using (SqlDataReader dr = mySQL.RunDataReader("dbo.sproc_Flow_GetParentProject", p2))
            {
                lbProject.Items.Clear();
                while (dr.Read())
                {
                    lbProject.Items.Add(new ListItem(dr["ClassName"].ToString(), dr["ClassID"].ToString()));
                }
            }
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            DocumentFlow.DeleteDocument(DocID);
            Server.Transfer("Listview.aspx");
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (lbProject.SelectedIndex >= 0)
            {
                long ProjectID = Int32.Parse(lbProject.Items[lbProject.SelectedIndex].Value);
                // DocumentFlow.DoMessage(df.PostDocument(UserName,DocID,DefineID,ProjectID),DocID);

                Server.Transfer("ListDocument.aspx?DisplayType=1");
            }
            else
            {
                Response.Write("<script language='javascript'>alert('请选择一个项目！');</script>");
            }
        }
    }
}